package pjn;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;

public class MultiWordCharacterHelper {

    private Set<String> multiWordNames = new HashSet<String>();
    private Map<String, Set<Integer>> namesOccurenceSentences = new HashMap<String, Set<Integer>>();
    private Map<String, Boolean> correctOrders = new HashMap<String, Boolean>();

    public MultiWordCharacterHelper(String multiWordName, Integer sentenceNumber, boolean correctOrder) {
        this.multiWordNames.add(multiWordName);
        this.correctOrders.put(multiWordName, correctOrder);
        addNameOccurenceSentence(multiWordName, sentenceNumber);
    }

    public Set<String> getMultiWordNames() {
        return multiWordNames;
    }

    public void addMultiWordName(String multiWordName) {
        this.multiWordNames.add(multiWordName);
    }

    public boolean isCorrectOrder(String name) {
        return correctOrders.get(name);
    }

    public void addCorrectOrder(String name, boolean correctOrder) {
        correctOrders.put(name, correctOrder);
    }

    public void addNameOccurenceSentence(String name, Integer sentenceNumber) {
        Set<Integer> sentenceNumbers = namesOccurenceSentences.get(name);

        if (sentenceNumbers == null) {
            sentenceNumbers = new TreeSet<Integer>();
            namesOccurenceSentences.put(name, sentenceNumbers);
        }
        sentenceNumbers.add(sentenceNumber);
    }

    public Map<String, Set<Integer>> getNamesOccurenceSentences() {
        return namesOccurenceSentences;
    }

    @Override
    public String toString() {
        StringBuffer buffer = new StringBuffer();
        for (String name : multiWordNames) {
            buffer.append(name);
            buffer.append(" - ");
            try {
                buffer.append(correctOrders.get(name).toString());
            } catch (Exception e) {
                buffer.append("ERROR");
            }
            buffer.append("\n");
        }

        return buffer.toString();
    }
}
